Multiple string searching using ternary content addressable memory

ABSTRACT

Disclosed herein is a method and apparatus for multiple string searching using a ternary content addressable memory. The method includes receiving a text string having a plurality of characters and performing an unanchored search of a database of stored patterns matching one or more characters of the text string using a state machine, wherein the state machine comprises a ternary content addressable memory (CAM) and wherein the performing comprises comparing a state and one of the plurality of characters with contents of a state field and a character field, respectively, stored in the ternary CAM. In the method and apparatus described herein, one or more of the following search features may be supported: exact string matching, inexact string matching, single character wildcard matching, multiple character wildcard matching, case insensitive matching, parallel matching and rollback.

CROSS-REFERENCE TO RELATED APPLICATION

This application is a divisional application and claims the benefitunder 35 USC §120 of the commonly owned U.S. patent application Ser. No.11/780,391 entitled “Multiple String Searching Using Ternary ContentAddressable Memory” filed on Jul. 19, 2007, now issued as U.S. Pat. No.7,440,304, which is a divisional of the commonly owned U.S. patentapplication Ser. No. 10/700,722 entitled “Multiple String SearchingUsing Content Addressable Memory” filed on Nov. 3, 2003, now issued asU.S. Pat. No. 7,634,500, both of which are incorporated herein byreference.

FIELD OF INVENTION

This invention relates to the field of string search devices and, inparticular, to the use of a content addressable memory device to performsearches for multiple strings.

BACKGROUND

The problem of string searching occurs in many applications. The stringsearch algorithm looks for a string called a “pattern” within a largerinput string called the “text.” Multiple string searching refers tosearching for multiple such patterns in the text string without havingto search multiple passes. In a string search, the text string istypically several thousand bits long with the smallest unit being oneoctet in size. The start of a pattern string within the text istypically not known. A search method that can search for patterns whenthe start of patterns within the argument text is not known in advanceis known as unanchored searching. In an anchored search, the searchalgorithm is given the text along with information on the offsets forstart of the strings.

A generalized multiple string search is utilized in many applicationssuch as URL based switching, Web caching, XML parsing, text compressionand decompression, analyzing DNA sequences in the study of genetics andintrusion detection systems for the internet. In string searchingapplications, an argument text is presented to the string search engine,which then searches this text for the occurrence of each of a multiplepatterns residing in a database, as illustrated in FIG. 1. If a match isfound, then an index or code that uniquely identifies the matchingpattern entry in the database is returned along with a pointer (offset)to the matching position in the input text string. The pointer indicatesthe number of characters positions that are offset from the startingcharacter of the string for which a matching pattern in the database isfound in the input text string.

For example, consider the input text string: “We hold these truths to beself-evident, that all men are created equal, that they are endowed bytheir Creator with certain unalienable Rights, that among these areLife, Liberty and the pursuit of Happiness.” Assume that the pattern“that” is stored in the pattern database as a first pattern (Pattern 1)and the pattern “are” is stored in the pattern database as a secondpattern (Pattern 2). For the two pattern strings “that” and “are,” astring search engine utilizing a matching algorithm may output a resultof Offset-41/Pattern 1 because the pattern “that” was found as a patternin the database and the first character “t” in the pattern “that” isoffset 41 places from the starting character “W” of the input textstring. The other results, for example, would be as follows:Offset-54/Pattern 2; Offset-73/Pattern 1; Offset 83/Pattern 2; Offset145:/Pattern 1; Offset 162/Pattern 2.

Some prior string search engines are based on software algorithms suchas Boyer-Moore that are inherently slow and have limited throughput.Other prior string search engines utilize the Aho-Corasick algorithm forstring matching in which either a static random access memory (SRAM) orcontent addressable memory (CAM) based lookup table is used to implementstate transitions in the string search engine. One problem with priorstring search engines utilizing the Aho-Corasick algorithm, such asdisclosed in U.S. Pat. No. 5,278,981, is that that they are incapable ofperforming wildcard or inexact matching. While some prior methods arecapable of performing wildcard matching such as disclosed in U.S. Pat.No. 5,452,451, the inexact matching feature is limited only to prefixesin text strings. Moreover, such prior methods are only capable ofanchored searches in which the start of patterns within the incomingtext string must be known and identified to the search engine. Further,such prior methods are not capable of case insensitive matching that isrequired in many applications. In addition, for a given patterndatabase, such prior methods require a large number of entries in a CAMdevice. In addition, the prior methods are not capable of increasing thesearch speed by processing multiple octets from the text stringconcurrently.

BRIEF DESCRIPTION OF THE DRAWINGS

The present invention is illustrated by way of example and not intendedto be limited by the figures of the accompanying drawings.

FIG. 1 is a conceptual illustration of string searching.

FIG. 2A illustrates one embodiment of a string search apparatus.

FIG. 2B illustrates one embodiment of the string search apparatus ofFIG. 2A.

FIG. 3A illustrates one embodiment of a ternary CAM.

FIG. 3B illustrates one embodiment of fields of a ternary CAM and anassociate memory.

FIG. 4A is a state transition flowchart illustrating one embodiment ofgoto-failure method using an exemplary set of patterns.

FIG. 4B illustrates an exemplary implementation of the goto-failuremethod of FIG. 4A.

FIG. 4C illustrates exemplary contents of one embodiment of a databasehaving compressed entries implementing the goto-failure method of FIG.4A.

FIG. 5 is a state transition flowchart illustrating one embodiment of adeterministic method for handling state transitions using the sameexemplary set of patterns of FIG. 4A.

FIG. 6 illustrates an exemplary contents of one embodiment of a databaseimplementing the deterministic method of state transitions of FIG. 5.

FIG. 7 is a flow chart illustrating one embodiment of a case insensitivesearch method.

FIG. 7A shows the ASCII encoded character set.

FIG. 7B shows one embodiment of a translation unit.

FIG. 7C shows one embodiment of the character set after translation.

FIG. 8A is a flow chart illustrating one embodiment of a method ofwildcard matching.

FIG. 8B illustrates one embodiment of a search string apparatusillustrating components implementing wildcard matching.

FIG. 8C illustrates an embodiment of exemplary TCAM and associatedmemory fields implementing wildcard matching.

FIG. 8D illustrates an alternative embodiment of a wildcard matchingmethod with a fixed number of wildcard characters.

FIG. 8E illustrates an alternative embodiment of a wildcard matchingmethod capable of searching for nested wildcard patterns.

FIG. 9A is a state diagram illustrating a parallel matching method usingan exemplary set of patterns.

FIG. 9B illustrates exemplary fields in an entry in a TCAM and exemplaryregisters in control circuitry.

FIG. 9C illustrates an exemplary embodiment of TCAM and associatedmemory fields.

FIG. 10A is a state diagram illustrating a rollback method for handlingstate transitions using the exemplary pattern set of FIG. 9A.

FIG. 10B illustrates entries that may be in a FIFO.

FIG. 10C is a state diagram illustrating a rollback method for handlingstate transitions using the exemplary pattern set of FIG. 9A.

FIG. 10D illustrates an exemplary embodiment of TCAM and associatedmemory fields for a rollback matching method.

FIG. 11 is a conceptual illustration showing a string matching apparatushandling multiple flows.

DETAILED DESCRIPTION

In the following description, numerous specific details are set forthsuch as examples of specific, components, circuits, processes, etc. inorder to provide a thorough understanding of the present invention. Itwill be apparent, however, to one skilled in the art that these specificdetails need not be employed to practice the present invention. In otherinstances, well known components or methods have not been described indetail in order to avoid unnecessarily obscuring the present invention.

Embodiments of the present invention include various method steps, whichwill be described below. The steps may be performed by hardwarecomponents or may be embodied in machine-executable instructions, whichmay be used to cause hardware components (e.g., a processor, programmingcircuit) programmed with the instructions to perform the steps.Alternatively, the steps may be performed by a combination of hardwareand software.

Embodiments of the present invention may be provided as a computerprogram product, or software, that may include a machine-readable mediumhaving stored thereon instructions. The machine readable medium may beused to program a computer system (or other electronic devices) togenerate articles (e.g., wafer masks) used to manufacture embodiments ofthe present invention. The machine-readable medium may include, but isnot limited to, floppy diskettes, optical disks, CD-ROMs, andmagneto-optical disks, ROMs, RAMs, EPROMs, EEPROMs, magnet or opticalcards, flash memory, or other type of media/machine-readable mediumsuitable for storing electronic instructions.

The machine readable medium may store data representing an integratedcircuit design layout that includes embodiments of the presentinvention. The design layout for the integrated circuit die may begenerated using various means, for examples, schematics, text files,gate-level netlists, hardware description languages, layout files, etc.The design layout may be converted into mask layers for fabrication ofwafers containing one or more integrated circuit dies. The integratedcircuit dies may then be assembled into packaged components. Designlayout, mask layer generation, and the fabrication and packaging ofintegrated circuit dies are known in the art; accordingly, a detaileddiscussion is not provided.

It should be noted that the steps and operations discussed herein (e.g.,the loading of registers) may be performed either synchronously orasynchronously. The term “coupled” as used herein means connecteddirectly to or connected through one or more intervening components orcircuits. Any of the signals provided over various buses describedherein may be time multiplexed with other signals and provided over oneor more common buses. Additionally, the interconnection between circuitelements or blocks may be shown as buses or as single signal lines. Eachof the buses may alternatively be single signal lines, and each of thesingle signal lines may alternatively be buses. Additionally, the prefixsymbol “/” or the suffix “B” attached to signal names indicates that thesignal is an active low signal. Each of the active low signals may bechanged to active high signals as generally known in the art.

A method and apparatus for text string matching is disclosed. In oneembodiment, the method includes receiving a text string having aplurality of characters and using a state machine to perform a search ona database to locate instances of specific pattern strings in the textstring. In one embodiment, the state machine includes a ternary CAMsearch engine. Performing the pattern search may include comparing astate and one of the plurality of characters in the text string with acurrent state and a current character, respectively, stored in theternary CAM.

For one embodiment, the state machine looks for occurrence of one ormore patterns stored in the database that match one or more charactersin the text. If a match is found, then an index that uniquely identifiesthe matching pattern in the database is returned along with an offsetpointer to the matching position in the input text string. The pointerindicates the number of character positions that are offset from thestarting character of the string for which a matching pattern in thedatabase is found in the input text string. In one particularembodiment, the string matching apparatus may support the search of textstring width's greater than the width of a row of CAM cells in theternary CAM array.

In various embodiments, one or more of the following database searchfeatures may be supported: exact string matching, inexact stringmatching, single character wildcard matching (e.g., the pattern “Jo?n”where ? represents any single character, with such a pattern capable ofmatching incoming text string such as “John” “Joan” and “Join” but not“Jon” or “Johan”), multiple character wildcard matching (e.g., thepattern “John had a # day” where # represents 0 or more characters, withsuch a pattern capable of matching an incoming text string such as “Johnhad a good day” or “John had a AAABBB day”), case insensitive matching,parallel matching and rollback optimization, as discussed in furtherdetail below.

FIG. 2A illustrates one embodiment of a string search apparatus. Stringsearch apparatus 200 includes control circuitry 210 coupled to patternand state database 215. Control circuitry 210 is configured to receivean input text string 205 having a plurality of characters from anotherdevice such as a processor 100. (e.g., a network processor unit (“NPU”),microprocessor, or other control device including, for example, anApplication Specific Integrated Circuit “ASIC” or the like). The controlcircuitry 210 is coupled to pattern and state database 215 to perform asearch of the database for a stored pattern matching one or morecharacters of the input text string 205. Each character in the inputtext string may be encoded in one of the many encoding schemes known inthe art, such as ASCII or EBSDIC. Typically, each character is encodedinto one octet, although other encodings may be used. In one particularembodiment, the control circuitry 210 processes one character from theinput text string at a time. Alternatively, control circuitry 210 mayprocesses multiple characters at a time when a higher search rate isrequired. The multiple characters may be presented to control circuitry210 at the same time or sequentially in time.

FIG. 2B illustrates one particular embodiment of string search apparatus200 of FIG. 2A. In this embodiment, search string apparatus 200 includescontrol circuitry 210, search engine 220 and associated memory 230 thattogether operate as a state machine. Search engine 220 and associatedmemory 230 together form one embodiment of pattern and state database215 of FIG. 1.

Search engine 220 implements the string search function using a statetransition scheme. The state transition information is collectivelystored in the pattern and state database 215. Patterns are encoded inthe search engine as a series of entries. In one embodiment, each entryin the search engine 220 is a concatenated word that includes onecharacter of the pattern and the corresponding state information. Thecontrol circuit 210 forms the search key (i.e., comparand) byconcatenating one character from the input text with the current stateinformation. The current state may be a null or idle state at power on.The control circuit 210 presents this concatenated search key to thesearch engine, which then searches through its entries. If there is amatch, search engine 220 outputs a match index 225 that uniquelyidentifies the matching location in the search engine. If there aremultiple matches, then the index corresponding to the highest priorityis presented as index 225. Associated memory 230 receives the matchindex and returns data 235 stored therein. Associated memory 230 storesnext state information and may store other information such as resultsand actions to be taken.

When associated memory 230 returns the next state information, the nextstate information is written to the current state register or variable,and a new search may be performed of on the database stored in searchengine 220. The above process repeats until an action is indicated bydata 235 that halts the process. The control circuitry 210 may keeptrack of an offset that indicates the number of character positions thatare offset from the starting character of the input text string 205 forwhich a matching pattern in the pattern and state database 215 is foundand output the same to the processor 100 as results 250.

In one particular embodiment, search engine 220 implements theAho-Corasick algorithm. Alternatively, the scheme described herein mayalso be used to implement any large state machine involving a largenumber of states that may not be practical to implement by conventionalmeans.

In one particular embodiment, associated memory 230 may be a randomaccess memory (RAM) such as a static RAM (SRAM) or dynamic RAM (DRAM).In another embodiment, associated memory 230 may be a flash memory.Alternatively, another memory device, for example, a read only memory(ROM), such as an erasable programmable ROM (EPROM) or EEPROM may beused for memory 230.

In one embodiment, the search engine 220 comprises a ternary CAM (TCAM).Although discussed below in relation to a TCAM, in alternativeembodiments, search engine 220 may be another type of search engine, forexample, a hash based search engine or a trie based search engine. Inone particular embodiment, a NSE5512 or NSE5526 ternary CAM availablefrom NetLogic Microsystems, Inc. may be used for search engine 220.Alternatively, other search devices from NetLogic Microsystems, Inc. orfrom other vendors may be used.

FIG. 3A illustrates one embodiment of a ternary CAM although otherembodiments may be used. Ternary CAM 220 includes ternary CAM array 302,address decoder 304, priority encoder 306, flag logic 308, comparandregister 310, instruction decoder 314, read/write circuit 312, and oneor more global mask registers 311.

Ternary CAM array 302 includes rows of CAM cells for storing patterndata, and corresponding rows of mask cells for storing mask data. Theternary CAM array 302 can effectively store three states of information,namely: a logic one state, a logic zero state, and a “don't care” statefor search or compare operations. The CAM array 302 cells may be anytypes of CAM cells including, for example, NAND and NOR based cells thatmay be formed from either volatile or non-volatile elements. Each CAMcell includes at least one memory storage element and at least onecompare circuit. Other embodiments may be used to effectively implementan array 302 of CAM cells.

CAM words 0 to N−1 are each capable of storing a set of bits that may bereceived by comparand bus CBUS 326. CBUS 326 may be configured toreceive search key 211 of FIG. 2B. Data may be read from or written toTCAM array 302 over data bus DBUS 350 by read/write (R/W) circuit 312that includes one or more sense amplifiers and one or more writedrivers. Each CAM word 0 to N−1 is coupled to a match line 322 ₀ to 322_(N), respectively. The match lines indicate whether comparand datamatched data stored in CAM words 0 to N−1. Match lines 322 ₀ to 322 _(N)are provided to flag logic 308 which generates a match flag signal/MF online 334 indicating whether a match has occurred. Additional flags suchas a multiple match flag may also be generated by flag logic 308. Flaglogic 308 may also be incorporated into priority encoder 306. Matchlines 322 ₀ to 322 _(N) are also coupled to priority encoder 306. If oneof the match lines indicates a match between the search key and datastored at a corresponding location in TCAM array 302 (as masked by itslocal mask if set), priority encoder 306 outputs an index (e.g., anaddress) on RBUS 332 that uniquely identifies the location of thematching location in TCAM array 302. If more than one match is detectedon match lines 322 ₀ to 322 _(N), priority encoder outputs the indexassociated with the highest priority entry in TCAM array 302. Thehighest priority entry may be located at the lowest physical address inTCAM array 302, at the highest physical address in TCAM array 302, ormay use any other predetermined priority resolution scheme includingoperating on priority values explicitly stored with entries in TCAMarray 302. Each CAM word 0 to N−1 has an associated local mask word 0 toN−1 that stores mask data for the CAM word. In contrast to global maskregisters that mask entire columns of CAM cells, the local mask wordsinclude local mask cells 361 that mask individual CAM cells 363 of acorresponding CAM word on a bit-by-bit basis. The local mask cells mayinclude memory cells for storing mask data. Each local mask word mayinclude as many local mask cells 361 as there are corresponding CAMcells 363. For an alternative embodiment, there may be only as manylocal mask cells 361 as are required for masking corresponding CAM cells363. For example, there may be less local mask cells 361 than CAM cells363 if each of the CAM cell 363 will need not need to be masked. Foralternative embodiments, the CAM words and local mask words may beencoded together to implement a ternary or quaternary function (storingeffectively four states; namely, a 0, 1, always match or always mismatchstate).

One or more global masking circuits (e.g., global mask 311) may becoupled between comparand register 310 and TCAM array 302 to mask entirecolumns in the TCAM array 302. It should be noted that TCAM 220 mayinclude fewer components (e.g., comparand register may be omitted) oradditional components than those shown in FIG. 3A. As ternary CAMs areknown in the art, a more detailed transistor level description is notprovided.

FIG. 3B illustrates one embodiment of fields that can be stored in oneor more rows of TCAM cells of search engine 220, and one embodiment offields that can be stored in one or more rows of memory cells inassociated memory 230. In this embodiment, the TCAM fields include astate (STATE) field 351, a pattern character (CHAR) field 352, and theassociated memory 230 fields include a next state (NXT_STATE) field 353,an action (ACTION) field 354, and a result (RSLT) field 355. The statefield 351 and the character field 352 together identify a statetransition. The size (e.g., the number of bits) allotted to fields 351and 352 depends on the maximum number of states expected in the patternand state database 215. The next state field 353 uniquely identifies thenext state for a given comparand that matches a corresponding state andcharacter in fields 351 and 352, respectively. The action field 354contains an opcode that provides control information to controlcircuitry 210 indicating the action to be taken by string searchapparatus 200. In one embodiment, for example, the action field may be 3bit encoded with: a 000 value indicating no action, advance to nextcharacter (NOP); a 001 value indicating emit result stored in the resultfield and advance to the next character in the input text string; and a010 value indicating a failure with no advancement to the next characterin the input text string. The size (e.g., the number of bits) allottedto field 354 depends on the maximum number of actions expected for thepattern and state database 215. The result field 355 contains a resultcode to be output from database 215 depending on the action. The size(e.g., the number of bits) allotted to field 355 depends on the maximumnumber of patterns in the pattern and state database 215.

In one particular embodiment, TCAM search engine 220 implements anAho-Corasick (AC) algorithm. The AC algorithm uses finite stateautomata, also known as a state machine. Several methods for handlingstate transitions may be used when implementing the AC algorithm. In oneembodiment, the method is a goto-failure method that achieves areduction in the number of state transitions at the expense of lowerthroughput. In a given state, if any of the expected characters in anyof the patterns is received, then the state machine goes to the nextstate. When the next character is not one of the expected characters, afailure link is taken to the state representing the longest prefixpossible with the current state.

Goto-Failure Method

FIG. 4A is a state transition flow chart illustrating the goto andfailure method for handling state transitions using an exemplary set ofpatterns {he, she, his, hers}. A “goto” transition transitions to a newstate while advancing to the next character in the input text. A“failure” transition advances to a new state, but does not advance tothe next character in the input text. Consider the state “she” 481. Ifthe character “r” is received, the logical next state should be “her.”However, the failure transition 461 jumps to state “he” 482 and oncethis state is reached, the character “r” 483 is considered again to makethe correct state transition to “her” state 484.

The goto-failure method may be implemented using two tables to encodestate-to-state transitions. The first table is a “goto” table that givesthe next state value if a current character matches the expectedcharacter for this state. If there is no match in the first “goto”table, then the second table is used, which is a “failure” table thatgives the state transition (a failure transition) if any other characteris received. A failure transition may take the state back to the “idle”state in some cases. However, the next character can also take it to astate corresponding to a different pattern. Failure transitions reducethe throughput because the string search apparatus 200 advances to thenext character only on a “goto” transition.

This goto-failure method may be implemented in TCAM search engine 220and associated memory 230 by, for example, dividing TCAM search engine220 into two blocks, as illustrated in FIG. 4B. The states in the tablesof FIG. 4B may be identified with a unique descriptive string associatedwith the state for ease of discussion. In an actual implementation ofthe tables in TCAM search engine 220 and associated memory 230, eachstate is represented by a corresponding unique number.

All the goto transitions of the first table may be placed in a firstgoto block 491 with a higher priority (e.g., at a lower address). Eachgoto transition translates to one entry in the TCAM search engine 220and one entry in associated memory 230. Within the goto block 491, therelative placement of the different transitions may not be importantbecause only one of the entries in this block will match. All thefailure transitions of the second table may be in a second block,failure block 492, following the first goto block 491. The relativeposition of the failure block means that its entries have a lowerpriority compared to the entries in goto block 491. The entries in thefailure block 492 will match only if there was no match in the gotoblock 491.

In one embodiment, the goto-failure method may be optimized bycompressing the entries in the blocks, as illustrated in FIG. 4C below.In this embodiment, all failure transitions to the state IDLE (e.g., asshown by the four failure transition IDLE states 471-474 of FIG. 4B) arecaptured by a single entry 475, for example, at the lowest priorityentry of TCAM search engine 220 that has all the entries masked(represented by the * in the state field 351 and character field 352)and, therefore, will always result in a match.

The goto-failure method requires two look-ups for one incoming characterin case the failure transition is taken, thereby resulting in reducedsearch speed. In an alternative embodiment, a deterministic method maybe used that eliminates failure transitions. In this embodiment, statetransitions may be increased with the string search apparatus 200 makingexplicit transition from each state for each character.

Deterministic Method

FIG. 5 is an exemplary state transition diagram illustrating adeterministic method for handling state transitions using the sameexemplary set of patterns of FIG. 4A. The deterministic method describedbelow achieves a higher speed than the goto-failure method describedabove, but at the cost of extra transitions. In this embodiment, in eachstate, only one transition leads to the valid next state. This method isdeterministic, since each character results in one lookup. Thetransitions shown in FIG. 5 with the dashed lines are the newtransitions over the state transitions of the goto-failure method shownin FIG. 4A. In addition, for the sake of clarity, the transitions fromany state to the “idle” state 510 and the transitions back to state “h”486 and state “s” 487 are not shown. The deterministic implementationadds additional transitions shown with the dashed lines 451-455 to thegoto block 491 of FIG. 4B. It should be noted that not all transitionsare shown for clarity. As an example consider the character “h” 586 isreceived in any state including the idle state 510, the state shouldtransition to the state “h” 486 if “h” is not a regular transition. Onesuch state transition 459 is marked with double line arrow going fromstate “he” 488 back to state “h” 486 upon receiving the character “h”586. The rest of such transitions, although required, are not shown forclarity. A brute force implementation in one embodiment would have oneTCAM search engine 220 entry (and associated memory entry 230) for eachof the transitions. The implementation of such a brute force embodimentwill end up with 31 entries for the example shown. The use of theternary feature of TCAM search engine 220 lends itself to a very goodcompression of the entries. The entries can be reduced, for example, bydividing the entries in to three blocks as illustrated in FIG. 6.

FIG. 6 illustrates an exemplary structure of one embodiment of a patternand state database implementing a deterministic method of statetransitions. Pattern and state database 215 may be divided into threeblocks: “block 1” 591, “block 2” 592 and “block 3” 593. These blockscorrespond to the relative position of a state in the state transitiondiagram FIG. 5. The block 593 with the lowest priority corresponds tothe state “idle”. This is the default entry that always goes back toidle state 510, if there are no other matches. In such an embodiment,all transitions to idle state 510 can be achieved with the single lastentry of block 593. This entry will have all its fields masked (asindicated by the * in the state field 351 and the character field 352)and, hence, will always match resulting in a transition to the IDLEstate 510.

All transitions corresponding to the states immediately following the“idle” state 510, such as the state “h” 486 and state “s” 487, areimplemented using block 592 containing entries with the next higherpriority. These entries have the STATE field 351 masked out (asindicated by the * in this field). These entries will also take care ofa transition from any state to the next state shown, such as thetransition 459 shown by the double line arrow. All other transitions goin the highest priority block 591.

Case Insensitive Matching

FIG. 7 is a flow chart illustrating one embodiment of a case insensitivesearch method. In this embodiment, the method for handling statetransitions accommodates case insensitive matching. As an example of acase insensitive match, the pattern “she” should match “she” or “SHE”.Alternatively, case insensitive matching may be required on certainportions of the pattern. As an example, “she” should match “She” but not“SHE” in a case where case insensitive matching is only used for “s” and“S”. The case insensitive search method includes determining an encodingrelationship between an upper case character and a lower case characterat 710. Then, at 720, a comparison of the input text string 205 withpatterns stored in pattern and state database 215 is performed that isindependent of the case encoding relationship.

FIG. 7A shows the American Standard Code for Information Interchange(ASCII) format encoding 730, which is one possible encoding forcharacters. In one embodiment, the characters of incoming text string205 may be encoded in the seven bit ASCII format. A study of this formatreveals that there is a fixed relation between the encoding of lowercase and upper case characters. For example the lowercase character “a”is encoded in binary as 110 0001 (i.e., row 6=110 and column 1=0001).The upper case “A” is encoded as 100 0001. These two differ in bitposition 5. This is true for all other alphabet characters as well. Ifbit-5 can be masked out during a compare operation, case insensitivematching can be achieved. This rule applies to all the alphabeticcharacters. As already described, each position in a ternary CAM can beset to a “don't care”. In order to achieve the case insensitive matchingfor the text and patterns in the ASCII encoding example, bit-5 can belocally set to a “don't care” in all the patterns in the database wherecase insensitive matching is desired. The case insensitive matching canalso be achieved for all the patterns in the pattern and state database,for example, by setting a global mask such that bit-5 is masked. Inother example, extensions to the ASCII set such as the 8-bit ISO8859 mayalso be used.

Using the seven bit ASCII character set and masking bit-5 may, however,have an undesired side effect with respect certain special characterssuch as “[” that are also encoded in rows-4 and 5 along with thealphanumeric characters. If case insensitive matching is desiredglobally and so global masks are used and special characters 731 areused as part of pattern database, then incorrect operation may resultsince a character such as “[” will match both the characters “[” as wellas “{”. An alternative embodiment, a translation unit may be used totranslate the 7-bit incoming ASCII characters to 8-bit outgoingcharacters as shown in FIGS. 7B and 7C. The special characters nowappear in other unused rows in an expanded 8-bit table. While using oneextra bit, this scheme allows case insensitive matching without anyconstraints. This is made possible because of the extra code space thatis available in an 8-bit space. The translation scheme should be appliedto all the patterns stored in the database as well as to the incomingtext characters before they are used in any compare operations. Thescheme shown in FIG. 7C is exemplary and any similar translation schemecan be used to achieve the same end. For one embodiment, 7-bit to 8-bittranslation can be performed by translation unit 715 that may beincluded within pattern and state database 215. Translation unit 715 canbe, for example, a lookup table, combinatorial logic, and any form ofsoftware or hardware that performs the necessary translation.

Wildcard Matching

FIG. 8A is a flow chart illustrating one embodiment of a method ofperforming wildcard matching using state and pattern database 215. Insuch an embodiment, a search may be performed for patterns matching aninput text string 205 having one or more of the characters unspecified.When a wildcard match is performed, the input text string 205 containingthe wildcard may be conceptually split into, for example, twosub-patterns. The first sub-pattern contains the portion of the inputstring preceding the wildcard, called the prefix. The second sub-patterncontains the portion of the input text string 205 succeeding thewildcard, called the suffix. Wildcard matching is used to look for anypattern matching the given prefix and the suffix of the input textstring 205. As mentioned, the wildcard may comprise more than oneunspecified character. In other words, there can be any number ofintervening characters (including zero) between the prefix and thesuffix. Consider, for example, the pattern “T#BLE.” “T” is the prefix,“BLE” is the suffix, and “#” represents the arbitrary number ofunspecified intervening characters. The following patterns will matchthe above wildcard pattern: “TABLE,” “TROUBLE,” “TREMBLE,” and “TUMBLE.”

FIG. 8A illustrates an exemplary flow diagram for wildcard matching. At810, input information from the input string is searched against thestored patterns in the state and pattern database 215. At 820, a suffixis located and the process determines that a prefix corresponding tothis suffix was previously found, a wildcard match has been located anda result indicating the match is output at 821. If, at 830 however, aprefix is found, then at 831 the result code corresponding to the prefixis output from the pattern and state database 215 and is stored (e.g.,in the CUR_PREFIX 881 register shown in FIG. 8B). If, however, anon-wildcard match is found at 840, a result indicating this match isoutput at 841 and the process returns to 810. If no matches are locatedin the pattern and state database, the process performs 810 again withthe next character from input text.

FIG. 8B illustrates one embodiment of a string search apparatus that iscapable of performing wildcard matches. In this embodiment, controlcircuitry 210 includes First-In-First-Out (FIFO) storage circuit 871,state registers 880, counter 891, clear logic 831, result logic 837 andregister 815. For other embodiments, roll back circuitry 1070 may alsobe included.

FIFO storage circuit 871 is configured to receive characters of inputtext string 205, and outputs the characters to CUR_CHAR register 883 ofstate registers 880. In alternative embodiments, FIFO storage circuit871 may be omitted and the input text string provided directly toCUR_CHAR register 883 or to a translation unit (e.g., translation unit715 of FIG. 7B).

State registers 880 include multiple registers containing variousinformation used to perform a lookup in the ternary CAM array 302. Forexample, in the embodiment implementing wildcard matching, stateregisters 880 include current character (CUR_CHAR) register 883, acurrent state (CUR_STATE) register 884, a current prefix (CUR_PREFIX)register 881, and a count register 882. Alternatively, state registers880 may be a single register having multiple register bit positiongroups corresponding to registers 881-884.

State registers 880 provide the search key for TCAM search engine 220.TCAM search engine 220 looks for the occurrence of one or more patternsstored in CAM array 302 that match the information in state registers880. If a match is found then a search result is presented to associatedmemory 230 as a match index 225 corresponding to the matching locationin the TCAM array 302. The match index 225 is used as the address 231for a look-up of associated memory 230. Associated memory 230 storesadditional data such as the next state, result, and action. An exampleof an entry in associated memory 230 is shown as entry 838. Associatedmemory 230 is coupled to control circuitry 210 to transmit the nextstate, action and result code data to the control circuitry 210.

Associated memory 230 may be coupled to register 815 of controlcircuitry 210. As discussed above in regards to FIG. 8A, if a result isto be output at 821 and 841 in TCAM search engine 220, the result fromthe RESULT field of the corresponding entry in associated memory 230 isoutput for storage in register 815. For one embodiment, one or bits ofthe action field of a given entry in associated memory 230 can be usedto control loading into register 815. This result may then be outputfrom the apparatus 200 (e.g., to a processor such as processor 100).

The NXT_STATE field of entry 838 in associated memory 230 is coupled tocurrent state register 884, such that the next state informationcorresponding to the match index 225 is loaded into current stateregister 884.

The action and result code data from entry 838 are coupled to resultlogic circuit 837 that loads the RESULT data from associated memory 230into the CUR_PREFIX register 881 when a valid prefix result isencountered in a search of TCAM search engine 220.

The ACTION code is also provided to clear logic 831, for example, toassert a clear signal 832 that sets counter 891 to zero when a prefix inthe text string 205 is detected after a search on TCAM search engine220. For one embodiment, the action field may be 3 bits (A₂, A₁, A₀)encoded as follows: a 000 value indicating no action, advance to nextcharacter (NOP); a 001 value indicating emit result in the RESULT field;and a 010 value indicating a failure with no advancement to the nextcharacter. It should be noted again that the action field of associatedmemory 230 illustrated in FIG. 8B is only exemplary and the other actionfield codes/sizes and corresponding logic circuit configurations may beused.

Counter 891 is also coupled to receive an increment (INC) signal 833that increments counter 891 for every new character received by controlcircuitry 210. The operation of count register 882 and counter 891 isdiscussed in more detail below in relation to FIG. 8D. State registers880 are also coupled to receive a power-on reset (RESET) signal 889 thatloads an idle state in current state register 884.

It should also be noted that control circuitry 210 may not necessarilycontain all the components illustrated in FIG. 8B depending on whatdatabase search features may be supported by string search apparatus200. For example, in an embodiment that does not implement wildcardsearching, control circuitry 210 may not include clear logic 831,counter 891 and/or result logic 837. It should be also be noted that,alternatively, one or more of the component functions shown in thecontrol circuitry of FIG. 8B may be implemented within hardware orfirmware of processor 100.

Consider the following example of the operation of apparatus 200 tolocate a wildcard match in an input text string using FIGS. 8A-8C. FIG.8C illustrates an exemplary embodiment of TCAM search engine entries andassociated memory entries that may be used in conjunction with theembodiment of control circuitry 210 shown in FIG. 8B to store and searchfor the wildcard pattern “T#BLE”. Assume, for example, that stringsearch apparatus 200 is in an idle state and receives a first character“T” from input string 205. The IDLE state is currently loaded inCUR_STATE register 884 and the “T” is loaded into CUR_CHAR register 883and these contents are compared with the entries stored in TCAM searchengine 220. A match is detected at address zero with the prefix “T”, andthe NXT_STATE of IDLE is read from a corresponding entry in associatedmemory 230 and loaded into CUR_STATE register 884. Additionally, theRESULT value of “101” and an ACTION value of “UPDATE CUR_PREFIX” areread from the corresponding entry in associated memory 230. In responseto the action “UPDATE CUR_PREFIX”, result logic 837 loads the RESULTvalue of “101” into CUR_PREFIX register 881. Now assume that one or morecharacters other than “B” are received from the input string text 205and loaded into CUR_CHAR register 883. In each case, the TCAM searchengine will be searched and no match will be found. When a “B” isreceived from input string 205, it is loaded into CUR_CHAR register 883and the contents of registers 884, 883 and 881 (“IDLE”, “B”, and “101”,respectively) are compared with fields 351, 352 and 856, respectively,in each of the entries stored in TCAM search engine 220. A match isdetected at address one, and the NXT_STATE of “B” is read from acorresponding entry in associated memory 230 and loaded into CUR_STATEregister 884. Additionally, the RESULT value of “0” and an ACTION valueof “NOP” are read from the corresponding entry in associated memory 230.In response to the action “NOP”, result logic 837 does not update thecontents of CUR_PREFIX register 881. If the next character received frominput text string 205 is an “L”, a match is detected at address two, theNXT_STATE of “BL” is loaded into CUR_STATE register 884, and theCUR_PREFIX register 881 is not updated. If the following characterreceived is “E”, a match is detected at address three, the NXT_STATE of“IDLE” is loaded into CUR_STATE register 884, the RESULT value of “102”and an ACTION value of “OUTPUT WILDCARD MATCH” are read from thecorresponding entry in associated memory 230. In response to the action“OUTPUT WILDCARD MATCH”, a wildcard match has been located because thesuffix “BLE” was found and the suffix “T” was previously found asindicated by match between the value “101” stored in CUR_PREFIX register881 and the value stored in field 856. The result 102 is loaded intoregister 815 and can be output from string search apparatus 200.

FIG. 8D illustrates an alternative embodiment of a wildcard matchingmethod with a fixed number of wildcard characters. In this embodiment, afixed number of wildcard characters are searched for rather than anunbounded number of intervening characters in a wildcard match. As anexample, consider the pattern “T??BLE” where each “?” represents asingle wildcard character. “TUMBLE” will match the pattern while“TROUBLE” and “TABLE” will not match because of the incorrect number ofintervening characters between the prefix “T” and the suffix “BLE”. Whenthe prefix is detected, in addition to storing the result in theprevious result register 881, the control circuitry 210 maintains acount of the characters in the input text string 205 after a prefixmatch. This may be implemented, for example, using an internal counter891. Internal counter 891 is set to zero when a prefix match is detectedand, for every new character received, counter 891 is incremented byone. The count in counter 891 is also stored in COUNT register 882 andcompared, along with the contents of registers 883, 884, and 881, withthe entries in TCAM search engine 220, which also include a COUNT field857. When a suffix pattern is detected, the values in the previousresult field 856 as well as the count field 857 must match thecorresponding values in the presented comparand in order for thewildcard pattern to be matched. As can be seen from FIG. 8D, when thesuffix “BLE” is detected (indicated by the address 3, current state 351entry of “BL” and the current character 352 entry “E”), if the inputtext string 205 was “TUMBLE” then the count in address 3 count field 857is 5, thereby resulting in a match because after “T” is detected thereare exactly five characters received including the suffix characters“BLE”. In the case of “TREMBLE,” then there would be three characters“REM” between “T” and “BLE” generating a count of 6. Such a count of 6will not result in a match.

FIG. 8E illustrates an alternative embodiment of a wildcard matchingmethod for identifying nested patterns. For example, assume two wildcardpatterns “S#BLE” and “T#BLE”, and an input text input string of“STABLE”. “TABLE” is nested within “STABLE”. As shown in FIG. 8E,different result codes can be used to identify different prefixes (orsuffixes) to accommodate nested wildcard patterns. For example, a firstresult code of “101” can be used for identifying the detection of theprefix “S”, a second result code of “102” can be used for identifyingthe detection of the prefix “T”. Additionally, two different resultcodes can be used to identify when a first wildcard is detected and asecond wildcard match is detected. For example, result code “103” can beused to identify when “T#BLE” is detected, and result code “104” can beused to identify when “S#BLE” is detected. In an alternative embodiment,the wildcard matching method can be enhanced to detect multiple nestedwildcard patterns by having multiple CUR_PREFIX registers in the controlcircuitry and also having multiple PREV_RSLT fields in the TCAM searchengine database 220. Additionally, the nested method can be extended forfixed number nested wildcard matching.

Parallel Matching

The methods described above are capable of very high speed searching.FIG. 9A illustrates an embodiment of a parallel matching method capableof increased search speeds.

In one embodiment, the speed of the matching method may be increased byincreasing the number of input characters that are compared at a timefrom the current one character to multiple characters. The one characterat a time method considered so far achieves unanchored pattern matching.In going from one character at a time matching to multiple charactermatching, the main problem to be solved is how to achieve unanchoredsearching. This section describes how to achieve an N fold increase insearch speed by considering N characters from the input text at a time.FIG. 9A illustrates an example of how to achieve 4× speedup by comparing4 characters at a time. Consider the text “OPTICAL COMMUNICATIONS” andfurther consider that we are looking for the pattern “COMMUNICATIONS”.When a set of 4 characters is presented to the string search apparatus,the start of the pattern within the text may be offset 0, 1, 2 or 3characters within this four character group. In one embodiment, all foursuch possibilities are represented in the pattern and state databasewith the first, second, third and fourth state entries being offset by0, 1, 2 and 3 characters, respectively. The string search apparatus 200considers all four entries in the database, COMM 910, *COM 920, **CO 930and ***C 940, in order to achieve an unanchored match (where the “*”denotes that the corresponding character in the database is masked out).Each of the states follows a separate branch path 901-904 through thestate machine until the result state 950 is reached. By following thesame search procedure for multiple patterns, the parallel matchingmethod achieves un-anchored multiple string matching. The parallelmatching method may be implemented in hardware by increasing the widthof the state register 890, and correspondingly, increasing the width ofthe entries in TCAM search engine 220, by a size corresponding to a sizeof the number of input characters (N) that are desired to be compared ata time. For example, as illustrated in FIG. 9B, if four characters willbe processed at one time, then four CUR_CHAR registers 883 ₁-883 ₄ maybe used and, correspondingly, four CHAR fields 352 ₁-352 ₄ may be usedin each entry of TCAM search engine 220.

FIG. 9C shows an exemplary implementation of the parallel matchingscheme. The TCAM and associate memory space is divided into four blocks960 ₁-960 ₄. The relative placement of the entries within a given blockdoes not affect the operation. Block 960 ₄ is the lowest priority block(e.g., has the highest addresses) and contains the default entry to IDLEstate. This entry will match when nothing else has matched. Block 960 ₃is the next higher priority block and contains all transitions to thefirst level states after IDLE (i.e., states 910, 920, 930, and 940). Allthese entries have their STATE masked. This serves both the transitionsfrom IDLE to the first level states as well as transitions from anyother state to the first level states. Block 960 ₂ is the next higherpriority block and contains all the entries where a result is output.The characters at the end that are not part of the pattern are maskedout. The next state is the IDLE state. Block 960 ₁ is the highestpriority block and contains all other entries. When a pattern isdetected, the end of that pattern may take all four or only a part ofthe block of four characters. In this case, a possibility exists thatthe remaining characters may be the start of a new pattern. Hence, allthe combinations of the end of the current pattern and start of all newpatterns need to be included. For example, the entry at address 5 has aCHARS state of “ONSC”. The first three characters “ONS” complete thecurrent pattern and the result is output. The last character “C” may bestart of a new pattern and hence the new state is “C”.

The input text should be presented to the search apparatus in multiplesof the set size (e.g., 4 characters as discussed above). When the lastset of characters in the text string are presented, it may not be equalto the full set size. In this case, the remainder of the characters inthe set can be set to an unused character that does not occur in any ofthe patterns in the database.

Rollback

In FIGS. 9A-9C, a large number of entries in the TCAM search engine 220may be used for combinations of one pattern followed immediately by asecond pattern. These entries can be eliminated and fewer entries neededin the TCAM search engine 220 through the use of a rollback method andapparatus described below. For one embodiment, FIFO storage circuit 871can be used to store several incoming characters of the incoming text,and a read pointer of FIFO 871 can be used to selectively read out thedesired characters stored in FIFO 871. A group of characters can be readfrom FIFO 871 and loaded into the corresponding CUR_CHAR registers. If,for example, the first two read characters match the end of a currentpattern, the remaining characters can be effectively ignored for thispass through the TCAM search engine 220. The remaining characters,however, remain stored in FIFO 871, and the read pointer of FIFO 871 canbe rolled back or selectively set to point to access the remainingcharacters as part of a new search. Associated memory 230 may includeone extra field per entry called the ROLLBACK field that identifies thenumber of characters that should be pushed or rolled back in FIFO 871.The rollback mechanism also allows further optimization by mergingseveral branches of the state machine in to one.

FIG. 10A is a state diagram illustrating a rollback method for handlingstate transitions using the exemplary patterns of FIG. 9A. In thisexemplary embodiment, for a given pattern, once the first N (e.g., four)characters are matched to a current state, then all the branches (e.g.,branches 1001-1004) of the state machine converge to a single commonlowest next state (e.g., state 1030) that is common to all the statetransitions. In this process, if some of the current states have alreadyprogressed to more characters in the pattern than the others, these arethen rolled back as shown in FIG. 10A.

In the exemplary state diagram of FIG. 10A, the pattern “COMMUNICATIONS”in the text string 205 is taken four characters at a time and exists asfour branches of state transitions in the database 215 with the first,second, third and fourth branches being offset by 0, 1, 2 and 3characters, respectively. The string search apparatus 200 considers allfour possible entries COMM 910, *COM 920, **CO 930 and ***C 940. If thenext four characters received in the input string 205 are “MUNI” 925,then the state machine transitions current state 920 to the *COMMUNI”next state 1030. If the next four characters received in the inputstring 205 are “UNI*” 915, then the state machine, which in theembodiment of FIG. 9A would have gone to the state “COMMUNIC”, insteadrolls back the state to “COMMUNI” state 1030, even though the “COMMUNI*”state transition branch 1001 had progressed to more characters (e.g., 8characters) than the “*COMMUNI” state transition branch 1002 (e.g.,having 7 characters).

As another example, consider the state COMMUN 937. If the next fourcharacters received in the input string 205 is “I***” 939, the statemachine rolls back to “COMMUNI” state 1030 (a common state to anotherstate transition branches) even though the “COMMUNI****” statetransition branch 1003 had progressed to more characters (e.g., 10characters) than the “COMMUNI” state transition branch 1004 (e.g.,having 7 characters).

An embodiment of entries in FIFO 871 for the rollback method is shown inFIG. 10B. The case shown in FIG. 10B is from the state “COMM” 910 andwhen the input text “UNIC” 915 is received. Once these four charactersare read, the read pointer points to the next valid character in theFIFO, which is character “A”. Due to the rollback mechanism, the statediagram transitions to the state “COMMUNI” 1030, and the read pointer isrolled back to position 1021 to ensure that the next four charactersread will be “CATI”, and the input text 205 and the current state are insynchronization again. In one embodiment, using a circular buffer sizeof N, the write process stops writing when the FIFO count reaches N−3 toprevent overwriting the useful data that may be required in case arollback takes place. The basic concept shown for a character-wide FIFOof FIG. 10B can be extended to the parallel implementation for increasedspeed.

FIG. 10C is a state diagram illustrating an alternative embodiment ofrollback method for handling state transitions. In this embodiment,depending on the state, the rollback method processes some of the inputtext string 205 characters twice. The read pointer is adjusted (rolledback) only when there is a partial match in the text with one of thepatterns stored in database 215. The probability of a rollback can bereduced if the algorithm looks for a longer match before resorting tothe rollback. FIG. 10C illustrates an example where the string searchapparatus 200 waits for a partial match of only 4 characters beforestarting the rollback.

Each entry in FIFO 871 may be wide enough (i.e., contain sufficientbits) to store one character at a time, or may be wide enough to storemultiple characters at a time. For one example, each entry of FIFO 871may be wide enough to store four characters in each entry.

In one embodiment, the rollback method discussed above with respect toFIGS. 10A-10C may be implemented in hardware by adding an extra field inthe associated memory 230 and by adding rollback circuit 1070 (see FIG.8B) in control circuitry 210. FIG. 10D illustrates an embodiment of theexemplary contents of a TCAM search engine 220 and associated memory 230implementing a rollback method. This extra field is a ROLLBACK (ROLLBK)field that contains the count of characters that are rolled back in FIFO871 before the start of a search.

FIG. 10D shows an exemplary implementation of the rollback schemedescribed in FIGS. 10A-10C. The TCAM and associate memory space isdivided into three blocks 1030 ₁-1030 ₃. Block 1030 ₃ is the lowestpriority block (e.g., has the highest addresses) and contains thedefault entry to transition to the IDLE state. Block 1030 ₂ is the nexthigher priority block and contains all the entries having as their nextstate (the CHARS state), the state after the IDLE state (i.e., states910, 920, 930 and 940). Block 10301 is the highest priority block andcontains all other entries. Looking at field entries 1042, 1043, 1044,and 1045, it can be seen that all four rows have the same next state. Ineffect, three of the input string entries are rolled back to match thestored pattern with the shortest match.

FIG. 11 is a conceptual illustration showing a string search apparatushandling multiple flows or contexts. In many applications, there is arequirement to handle multiple contexts. In one embodiment, for example,the string search apparatus 200 may be used in a networking system toswitch and/or route data between the network's transmission lines totransfer data payloads from a source to a destination. Data payloads aretypically transmitted in the form of packets that are made up of smallerdata cells. A packet is a unit of data that is routed between a sourceand a destination on a packet-switched network. Typically, a packet maytravel through a number of network points having routers before arrivingat its destination. When a data packet 1110 arrives at the input ofrouter 1100, several lookups may be performed to determine thesubsequent handling of packet 1110. Router 1100 may include processor100 and a string search apparatus 200 to perform the various packetforwarding lookups. The packet 1110 may be parsed by processor 100 toget one or more keys (e.g., a header) in order to perform the variouslookups.

Consider a typical Internet router employing the IPV4 based protocolsystem where multiple TCP/IP based connections exist. A single higherlayer data payload may be split across multiple TCP packets. MultipleTCP connections may exist. Each TCP connection may generate multiple TCPpackets. The TCP packets from different connections may be interleaved.Hence, when the TCP packets arrive at the string search apparatus, onechoice is to re-assemble packets that belong to each TCP connectionseparately so that the text for a given connection is presentedcontiguously to the string search apparatus. However this methodrequires extra memory and also involves other overhead such as memoryand protocol processing. An alternative embodiment considers each TCPconnection as a separate context. When all the characters of a packethave been processed, it stores the current state or context of thisconnection. When a packet belonging to the same connection is received,then it restores the context and re-starts the search. In order tosearch through a higher-level data payload, the string search apparatus200 switches between multiple contexts. This can be implemented as asimple table lookup (e.g., in memory 1120) to first fetch the context ofthe search. The context may include the parameters such as currentprefix, result code, remainder of characters that could not be processedfrom the current packet, roll back value and count as discussed above.In case of parallel searching, for the example shown, a set of fourcharacters is presented to the search apparatus. In case a packet is nota whole multiple of 4 characters long, a remainder number of characters,which may be up to 3 characters, may be left. These characters are savedas part of the context and combined with the next packet belonging tothe same TCP connection. The mechanism of saving and restoring thecontext allows the string search apparatus to handle multiple streams ofinput text that are interleaved in packets.

It should be noted that the string matching methods and apparatusdiscussed herein may be used in a wide variety of applications, forexamples, URL based switching, Web caching, XML parsing, intrusiondetection systems, implementation of data compression (e.g.,Limpel-Ziv), calculations of DNA sequencing, and others.

It should be noted that the circuitry associated with the operations ofa particular “diagram block” as illustrated within a “diagram block” isdone only for ease of discussion and that such circuitry may have othergroupings or physical locations within an apparatus.

In the foregoing specification, the invention has been described withreference to specific exemplary embodiments thereof. It will, however,be evident that various modifications and changes may be made theretowithout departing from the broader spirit and scope of the invention asset forth in the appended claims. The specification and drawings are,accordingly, to be regarded in an illustrative sense rather than arestrictive sense.

1. A search engine for implementing search operations between an inputstring of characters and a plurality of patterns embodied by a statemachine, the search engine comprising: a ternary content addressablememory (TCAM) having a plurality of rows each for storing a firstportion of a corresponding state entry of the state machine, wherein thefirst portion includes a state field, a character field, and a previousresult field; and an associated random access memory (RAM) having aplurality of rows each for storing a second portion of the correspondingstate entry, wherein the second portion includes a next state field anda result field.
 2. The search engine of claim 1, wherein the statefield, the character field, and the previous result field of the firstportion of each state entry are individually masked with respect to thefirst portions of other state entries.
 3. The search engine of claim 1,wherein the state and character fields of at least one of the stateentries consists of ternary don't care bits.
 4. The search engine ofclaim 1, wherein the first portion of each state entry further includesa count field.
 5. The search engine of claim 1, further comprising:control circuitry coupled to the TCAM and the associated RAM, whereinthe control circuitry includes a current state register, a currentcharacter register, and a current prefix register.
 6. The search engineof claim 5, wherein the first portion of each state entry furtherincludes a count field, and the control circuitry further comprises acount register.
 7. The search engine of claim 6, wherein the count fieldstores a count value indicative of a predetermined number of wildcardsin a corresponding one of the patterns.
 8. The search engine of claim 7,wherein the control circuitry further comprises a counter having aninput to receive an increment signal and having an output coupled to thecount register.
 9. The search engine of claim 5, wherein the controlcircuitry further comprises result logic configured to load a resultvalue from the result field of the associated RAM into the currentprefix register.
 10. The search engine of claim 5, wherein the contentsof the current prefix register are compared with the previous resultfields stored in the TCAM.
 11. A search engine for implementing searchoperations between an input string of characters and a plurality ofpatterns embodied by a state machine, the search engine comprising: aternary content addressable memory (TCAM) having a plurality of rowseach for storing a first portion of a corresponding state entry of thestate machine, wherein the first portion includes a state field and acharacter field; an associated random access memory (RAM) having aplurality of rows each for storing a second portion of the correspondingstate entry, wherein the second portion includes a next state field anda result field; and a control circuit coupled to the TCAM and theassociated RAM, wherein the control circuit comprises a current prefixregister.
 12. The search engine of claim 11, wherein the state andcharacter fields of at least one of the state entries consists ofternary don't care bits.
 13. The search engine of claim 11, wherein thecontrol circuit further comprises a current state register and a currentcharacter register.
 14. The search engine of claim 11, wherein thecontrol circuit further comprises result logic configured to load aresult value from the result field of the associated RAM into thecurrent prefix register.
 15. The search engine of claim 11, wherein thefirst portion of each state entry further comprises a previous resultfield.
 16. The search engine of claim 15, wherein the contents of thecurrent prefix register are compared with the previous result fieldsstored in the TCAM.
 17. The search engine of claim 11, wherein the firstportion of each state entry further includes a count field, and thecontrol circuit further comprises a count register.
 18. The searchengine of claim 17, wherein the count field stores a count valueindicative of a predetermined number of wildcards in a corresponding oneof the patterns.
 19. The search engine of claim 17, wherein the controlcircuit further comprises a counter having an input to receive anincrement signal and having an output coupled to the count register.